package com.bear.newsset.mvp.presen;

import androidx.annotation.NonNull;

import com.bear.newsset.R;
import com.bear.newsset.ui.fragment.ExploreFragment;
import com.bear.newsset.ui.fragment.HomeFragment;
import com.bear.newsset.ui.fragment.MeFragment;
import com.bear.newsset.util.FragmentManage;
import com.bear.newsset.mvp.view.MainView;
import com.ybear.ybmvp.enums.LIFE_STATUS;
import com.ybear.ybmvp.presenter.YBPresenter;

public class MainPresen extends YBPresenter<MainView> {
    private FragmentManage mFM;
    public MainPresen(@NonNull MainView view) {
        super(view);
        init();
    }

    private void init() {
        MainView mView = getView();
        if( mView == null ) return;
        mFM = FragmentManage.getInstance()
                .setFragmentActivity( mView.callMainActivity() )
                .setSuperLayoutID( R.id.main_frame_fragment )
                .setSingleBackStack( true );
    }

    public void switchFragmentHome() {
//        mFM.switchFragment( HomeFragment.class, R.anim.anim_right_in, R.anim.anim_left_out );
        mFM.switchFragment( HomeFragment.class, R.anim.anim_left_in, R.anim.anim_right_out );
    }

    public void switchFragmentExplore() {
        mFM.switchFragment( ExploreFragment.class, R.anim.anim_right_in, R.anim.anim_left_out );
    }

    public void switchFragmentMe() {
//        mFM.switchFragment( MeFragment.class, R.anim.anim_right_in, R.anim.anim_left_out );
        mFM.switchFragment( MeFragment.class, R.anim.anim_right_in, R.anim.anim_left_out );
    }

    @Override
    public void onLifeStatus(LIFE_STATUS status) {
        super.onLifeStatus(status);
        MainView mView = getView();
        if ( mView == null ) return;
        //生命周期在Resume时再次设置Fragment管理器的Activity
        if ( status == LIFE_STATUS.RESUME ) mFM.setFragmentActivity(mView.callMainActivity());
    }
}
